 package handling.world;

 import client.MapleBuffStat;
 import client.MapleCharacter;
 import client.MapleDiseaseValueHolder;
 import client.inventory.MapleInventoryType;
 import client.inventory.MaplePet;
 import client.inventory.PetDataFactory;
 import client.status.MonsterStatus;
 import client.status.MonsterStatusEffect;
 import client.status.NewMonsterStatusEffect;
 import handling.channel.ChannelServer;
 import java.util.List;
 import java.util.Map;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import server.Timer;
 import server.life.MapleMonster;
 import server.maps.MapleMap;
 import server.maps.MapleMapItem;
 import tools.Pair;











 public class WorldRespawnService
 {
/*  35 */   private static final Logger log = LogManager.getLogger(WorldRespawnService.class.getName());

   private WorldRespawnService() {
/*  38 */     log.info("正在启动[WorldRespawnService]");
/*  39 */     Integer[] chs = (Integer[])ChannelServer.getAllInstance().toArray((Object[])new Integer[0]);
/*  40 */     for (int i = 1; i <= chs.length; i++) {
/*  41 */       Timer.WorldTimer.getInstance().register(new Respawn(i), 1000L);
     }
   }

   public static WorldRespawnService getInstance() {
/*  46 */     return SingletonHolder.instance;
   }




   public static void handleMap(MapleMap map, int numTimes, int size, long now) {
/*  53 */     if (map.getItemsSize() > 0) {
/*  54 */       for (MapleMapItem item : map.getAllItemsThreadsafe()) {
/*  55 */         if (item.shouldExpire(now)) {
/*  56 */           item.expire(map); continue;
/*  57 */         }  if (item.shouldFFA(now)) {
/*  58 */           item.setDropType((byte)2);
         }
       }
     }



/*  65 */     boolean canSpawnRune = false;
/*  66 */     if (map.getCharactersSize() > 0 || map.getId() == 931000500) {



/*  70 */       if (map.canSpawn(now)) {
/*  71 */         map.respawn(false, now);
       }



/*  76 */       boolean hurt = map.canHurt(now);
/*  77 */       for (MapleCharacter chr : map.getCharactersThreadsafe()) {
/*  78 */         handleCooldowns(chr, numTimes, hurt, now);
       }



/*  83 */       if (map.getMobsSize() > 0) {
/*  84 */         for (MapleMonster mons : map.getAllMonstersThreadsafe()) {
/*  85 */           if (mons.getStats().getLevel() >= 30) {
/*  86 */             canSpawnRune = true;
           }
/*  88 */           if (mons.isAlive()) {

/*  90 */             if (mons.shouldKill(now)) {
/*  91 */               map.killMonster(mons);
             }

/*  94 */             if (mons.shouldDrop(now)) {
/*  95 */               mons.doDropItem(now);
             }

/*  98 */             if (mons.getStatiSize() > 0) {
/*  99 */               for (MonsterStatusEffect mse : mons.getAllBuffs()) {
/* 100 */                 if (mse.shouldCancel(now)) {
/* 101 */                   mons.cancelSingleStatus(mse);
                 }
               }
             }

/* 106 */             if (mons.getNewMobEffects().size() > 0) {
/* 107 */               for (Map.Entry<Integer, List<Pair<MonsterStatus, NewMonsterStatusEffect>>> entry : (Iterable<Map.Entry<Integer, List<Pair<MonsterStatus, NewMonsterStatusEffect>>>>)mons.getNewMobEffects().entrySet()) {
/* 108 */                 for (Pair<MonsterStatus, NewMonsterStatusEffect> pair : entry.getValue()) {
/* 109 */                   if (((NewMonsterStatusEffect)pair.getRight()).shouldCancel(now)) {
/* 110 */                     mons.cancelNewStatus(((Integer)entry.getKey()).intValue());
                   }
                 }
               }
             }
           }
         }
       }
     }
/* 119 */     if (canSpawnRune && map.getRunesSize() == 0 && !map.isBossMap() && map.getFirstUserEnter().equals("") && map.getUserEnter().equals("")) {
/* 120 */       map.respawnRune();
     }
   }




   public static void handleCooldowns(MapleCharacter chr, int numTimes, boolean hurt, long now) {
/* 128 */     if (chr == null) {
       return;
     }















/* 146 */     if (chr.isAlive()) {
/* 147 */       chr.doAnimabuff();
/* 148 */       if ((chr.getJob() == 131 || chr.getJob() == 132) && 
/* 149 */         chr.canBlood(now)) {
/* 150 */         chr.doDragonBlood();
       }

/* 153 */       if (chr.canRecover(now)) {
/* 154 */         chr.doRecovery();
       }

/* 157 */       if (chr.canRecoverCKZZ(now)) {
/* 158 */         chr.doRecoveryCKZZ();
       }


/* 162 */       if ((chr.getJob() == 3121 || chr.getJob() == 3122) && 
/* 163 */         chr.canRecoverEM(now)) {
/* 164 */         chr.doRecoveryEM();
       }

/* 167 */       if (chr.canHPRecover(now)) {
/* 168 */         chr.addHP((int)chr.getStat().getHealHP());
       }
/* 170 */       if (chr.canMPRecover(now)) {
/* 171 */         chr.addMP((int)chr.getStat().getHealMP());
/* 172 */         if (chr.getJob() == 3111 || chr.getJob() == 3112) {
/* 173 */           chr.addDemonMp((int)chr.getStat().getHealMP());
         }
       }

/* 177 */       if (chr.canRecoverPower(now)) {
/* 178 */         chr.doRecoveryPower();
       }
/* 180 */       if (chr.getLevel() >= 200) {
/* 181 */         chr.check5thJobQuest();
       }

/* 184 */       if (chr.canRecoverCrit(now)) {
/* 185 */         chr.handleCritStorage();
       }

/* 188 */       if (chr.canPartyPassiveBuff(now)) {
/* 189 */         chr.doPartyPassiveBuff();
       }
/* 191 */       if (chr.canFairy(now)) {
/* 192 */         chr.doFairy();
       }
/* 194 */       if (chr.canFish(now)) {
/* 195 */         chr.doFish(now);
       }
/* 197 */       if (chr.canExpiration(now)) {
/* 198 */         chr.expirationTask();
       }
/* 200 */       if (chr.canMorphLost(now)) {
/* 201 */         chr.morphLostTask();
       }
/* 203 */       if (chr.canRepeatEffect(now)) {
/* 204 */         chr.doRepeatEffect();
       }
     }



/* 210 */     if (chr.getDiseaseSize() > 0) {
/* 211 */       for (MapleDiseaseValueHolder m : chr.getAllDiseases()) {
/* 212 */         if (m != null && m.startTime + m.length < now) {
/* 213 */           chr.dispelDebuff(m.disease);
         }
       }
     }



/* 220 */     if (numTimes % 7 == 0 && chr.getMount() != null && chr.getMount().canTire(now)) {
/* 221 */       chr.getMount().increaseFatigue();
     }
/* 223 */     if (numTimes % 30 == 0) {
/* 224 */       for (MaplePet pet : chr.getSummonedPets()) {
/* 225 */         if (pet.getPetItemId() == 5000054 && pet.getSecondsLeft() > 0) {
/* 226 */           pet.setSecondsLeft(pet.getSecondsLeft() - 1);
/* 227 */           if (pet.getSecondsLeft() <= 0) {
/* 228 */             chr.unequipSpawnPet(pet, true, true);
             return;
           }
         }
/* 232 */         int newFullness = pet.getFullness() - PetDataFactory.getHunger(pet.getPetItemId());
/* 233 */         if (newFullness <= 5) {
/* 234 */           pet.setFullness(15);
/* 235 */           chr.unequipSpawnPet(pet, true, true); continue;
         }
/* 237 */         pet.setFullness(newFullness);
/* 238 */         chr.petUpdateStats(pet, true);
       }
     }

/* 242 */     if (hurt && chr.isAlive())
     {


/* 246 */       if (chr.getInventory(MapleInventoryType.EQUIPPED).findById(chr.getMap().getHPDecProtect()) == null)
/* 247 */         if (chr.getMapId() == 749040100 && chr.getInventory(MapleInventoryType.CASH).findById(5451000) == null) {
/* 248 */           chr.addHP(-chr.getMap().getHPDec());
/* 249 */         } else if (chr.getMapId() != 749040100) {
/* 250 */           chr.addHP(-(chr.getMap().getHPDec() - ((chr.getBuffedValue(MapleBuffStat.HP_LOSS_GUARD) == null) ? 0 : chr.getBuffedValue(MapleBuffStat.HP_LOSS_GUARD).intValue())));
         }
     }
   }

   private static class Respawn
     implements Runnable
   {
     private final ChannelServer cserv;
/* 259 */     private int numTimes = 0;

     public Respawn(int ch) {
/* 262 */       String sb = "[Respawn Worker] Registered for channel " + ch;
/* 263 */       this.cserv = ChannelServer.getInstance(ch);
/* 264 */       WorldRespawnService.log.info(sb);
     }


     public void run() {
/* 269 */       this.numTimes++;
/* 270 */       long now = System.currentTimeMillis();
/* 271 */       if (!this.cserv.hasFinishedShutdown()) {
/* 272 */         for (MapleMap map : this.cserv.getMapFactory().getAllLoadedMaps()) {
/* 273 */           WorldRespawnService.handleMap(map, this.numTimes, map.getCharactersSize(), now);
         }
       }
     }
   }

   private static class SingletonHolder
   {
/* 281 */     protected static final WorldRespawnService instance = new WorldRespawnService();
   }
 }


/* Location:              C:\PGX\Server.jar!\handling\world\WorldRespawnService.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */